//  Copyright (c) 2010 by Dolphin Technology
//  All rightseserved.
//
//  Copyright Notification
//  No part may be reproduced except as authorized by written permission.
// 
//% @file   dti_lfsr_load.v
//% @par    Company:
//%             Dolphin Technology 
//% @par    Project:
//%             [projectname]
//% @par    Author:
//%             N. Huy Bui
//% @par    Date:
//%             July 9, 2012
//% @brief
//%             parameterized LFSR counter
//$Id$

module dti_lfsr_load #(parameter WIDTH = 4) (
  input 	    clk,
  input 	    arst_n,
  input 	    c_en,
  input 	    load_n,
  input     [WIDTH-1:0] data_in,
  output reg [WIDTH-1:0] count);

reg 	  [WIDTH-1:0] count_next;
wire 		  linear_fb   = !(data_in [1] ^ data_in [0]);

//sequential block for updating next-state register
always @ (posedge clk or arst_n)
begin
  if (!arst_n)
    count <= 0;
  else
    count <= count_next;
end

//combinational block for calculating next-state logic
always @ (c_en, load_n, data_in, linear_fb, count)
begin
  if (!load_n)
    count_next = count ^ data_in;
  else if (!c_en)
    count_next = {linear_fb, count [WIDTH-1:0]};
  else
    count_next = count;
end

endmodule // dti_lfsr_load
